package com.supreme.secretserver.component;

import com.supreme.common.constant.ConsoleColors;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.secretserver.component.condition.WrapCondition;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

//@ControllerAdvice
@Conditional(value = WrapCondition.class)
public class WrapResponse implements ResponseBodyAdvice<AjaxResp> {

    @Override
    public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> clazz) {
        ConsoleColors.println(ConsoleColors.YELLOW_BOLD_BRIGHT, "WrapResponse supports");
        return true;
    }

    @Override
    public AjaxResp beforeBodyWrite(AjaxResp ajaxResp, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> clazz, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
        ConsoleColors.println(ConsoleColors.YELLOW_BOLD_BRIGHT, "WrapResponse beforeBodyWrite");
        return ajaxResp;
    }
}
